package services;

import java.util.List;

import models.DrSecret;
import models.SystemDict;
import models.SystemDictExample;
import models.mapper.DrSecretMapper;
import models.mapper.SystemDictMapper;
import models.mapper.SystemRoleMapper;

import org.apache.commons.lang.StringUtils;
import org.apache.ibatis.session.SqlSession;

import com.aton.db.SessionFactory;

import vos.Node;

/**
 * 字典表服务类
 * @author wangshaoming
 *
 */
public class DictService {
	/**
	 * 字典表中获取下拉框
	 * @param dictKey
	 * @return
	 */
	public static List<Node> getComboBox(String dictCode) {
		// TODO Auto-generated method stub
		SqlSession ss = SessionFactory.INSTANCE.getSqlSession();
		try{
			SystemDictMapper mapper=ss.getMapper(SystemDictMapper.class);
			return mapper.getComboBox(dictCode);
		}finally{
			ss.close();
		}
	}
	/**
	 * 获取角色下拉框
	 * @return
	 */
	public static List<Node> getRoleComboBox() {
		// TODO Auto-generated method stub
		SqlSession ss = SessionFactory.INSTANCE.getSqlSession();
		try{
			SystemRoleMapper mapper=ss.getMapper(SystemRoleMapper.class);
			return mapper.getRoleComboBox();
		}finally{
			ss.close();
		}
	}
	/**
	 * 获取密级下拉框
	 * @return
	 */
	public static List<Node> getSecretCombobox() {
		// TODO Auto-generated method stub
		SqlSession ss = SessionFactory.INSTANCE.getSqlSession();
		try{
			DrSecretMapper mapper=ss.getMapper(DrSecretMapper.class);
			return mapper.getRoleComboBox();
		}finally{
			ss.close();
		}
	}
	/**
	 * 根据id获取字典
	 * @param id
	 * @return
	 */
	public static SystemDict getById(String id){
		SqlSession ss = SessionFactory.INSTANCE.getSqlSession();
		try{
			SystemDictMapper mapper=ss.getMapper(SystemDictMapper.class);
			return mapper.selectByPrimaryKey(id);
		}finally{
			ss.close();
		}
	}
	/**
	 * 获取用户级别
	 * @param secretLevel
	 * @return
	 */
	public static List<Node> getUserSecretCombobox(String secretLevel) {
		// TODO Auto-generated method stub
		SqlSession ss = SessionFactory.INSTANCE.getSqlSession();
		try{
			DrSecretMapper mapper=ss.getMapper(DrSecretMapper.class);
			return mapper.getRoleLevelComboBox(secretLevel);
		}finally{
			ss.close();
		}
	}
	/**
	 * 根据id获取密级
	 * @return
	 */
	public static DrSecret getSecretById(String id) {
		// TODO Auto-generated method stub
		SqlSession ss = SessionFactory.INSTANCE.getSqlSession();
		try{
			DrSecretMapper mapper=ss.getMapper(DrSecretMapper.class);
			return mapper.selectByPrimaryKey(id);
		}finally{
			ss.close();
		}
	}
}
